package com.hmh.student.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmh.student.system.entity.SysMenu;
import com.hmh.student.system.entity.SysRole;
import com.hmh.student.system.entity.SysRoleMenu;
import com.hmh.student.system.entity.SysUserRole;
import com.hmh.student.system.mapper.SysMenuMapper;
import com.hmh.student.system.mapper.SysRoleMapper;
import com.hmh.student.system.mapper.SysRoleMenuMapper;
import com.hmh.student.system.service.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmh.student.system.service.ISysUserRoleService;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.management.relation.RoleNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xyf
 * @since 2025-04-15
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {



    @Autowired
    private SysRoleMapper sysRoleMapper;



   /* //新增
    @Override
    public void testRoleAdd(SysRole sysRole) {
        //将新增的角色保存到角色表
        this.save(sysRole);
        //将新增的角色绑定给超管（添加角色用户中间表）
        SysUserRole sysUserRole = new SysUserRole();
        sysUserRole.setRoleId(sysRole.getRoleId());
        sysUserRole.setUserId(1);

        sysUserRoleService.save(sysUserRole);

    }*/

    //修改

/*    @Override
    public void testRoleUpdate(SysRole sysRole) {

    }

public void testRoleDelete(Long roleId) {

}*/


//分页查询
    public Page<SysRole> queryRolePage(Page<SysRole>page, String roleName) {

        LambdaQueryWrapper<SysRole> la=new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(roleName)) {
            la.like(SysRole::getRoleName, roleName);

        }
        return this.page(page, la);
    }

    @Override
    public boolean existsById(Integer roleId) {
        if (roleId == null)  return false;
        return sysRoleMapper.selectCount(new QueryWrapper<SysRole>().eq("role_id", roleId)) > 0;
    }



}
